
scriptSupport.addInit(function() {
	if (window.name == "_responseData")
	  return;
	document.eventDebug = document.createElement("div");
	document.eventDebug.style.position = "absolute";
	document.eventDebug.style.top = "40px";
	document.eventDebug.style.right = "220px";
	document.eventDebug.style.fontSize = "50%";
	document.eventDebug.style.backgroundColor = "yellow";
	document.eventDebug.style.height = "90%";
	document.eventDebug.style.overflow = "auto";
  document.eventDebug.style.display = "none";
  document.eventDebug.innerHTML += "Event Debug:<br/>";
	document.eventDebug.mouseMoveRepeat = false;
	document.body.appendChild(document.eventDebug);
	
	new EventListener(document, "click", function(evn) {
	  document.eventDebug.innerHTML += "document-click: "+evn.button+"<br/>";
		document.eventDebug.mouseMoveRepeat = false;
	});
	
	
	new EventListener(document, "keydown", function(evn) {
	  if (evn.keyCode == 119) {
	  	// F8
	  	if (document.debugConsole)
	    	document.debugConsole.style.display =
	    	  (document.debugConsole.style.display == "none")?"block":"none";
	  }
		if (!document.eventDebug)
		  return;
	  if (evn.keyCode == 120) {
	  	// F9
	    document.eventDebug.style.display =
	      (document.eventDebug.style.display == "none")?"block":"none";
	  }
	  document.eventDebug.innerHTML += "document-keydown: "+evn.keyCode+"<br/>";
		document.eventDebug.mouseMoveRepeat = false;
	});
	
	
	new EventListener(document, "mouseup", function(evn) {
	  document.eventDebug.innerHTML += "document-mouseup: "+evn.button+"<br/>";
		document.eventDebug.mouseMoveRepeat = false;
	});
	
	new EventListener(document, "contextmenu", function(evn) {
	  document.eventDebug.innerHTML += "document-contextmenu: "+evn.target.nodeName+"<br/>";
		document.eventDebug.mouseMoveRepeat = false;
	});
	
	new EventListener(document, "mousemove", function(evn) {
		if (document.eventDebug.mouseMoveRepeat)
		  return;
		document.eventDebug.mouseMoveRepeat = true;
	  document.eventDebug.innerHTML += "document-mousemove<br/>";
	});
	
	new EventListener(document, "mousedown", function(evn) {
	  document.eventDebug.innerHTML += "document-mousedown: "+evn.button+"<br/>";
		document.eventDebug.mouseMoveRepeat = false;
	});
});


/**
  Report a message as an error in the JavaScript console.
 */
function debug(message) {
	if (!document.debugConsole) {
		document.debugConsole = document.createElement("div");
		document.debugConsole.style.position = "absolute";
		document.debugConsole.style.top = "40px";
		document.debugConsole.style.right = "20px";
		document.debugConsole.style.fontSize = "50%";
		document.debugConsole.style.backgroundColor = "#FFDDDD";
		document.debugConsole.style.height = "90%";
		document.debugConsole.style.overflow = "auto";
	  //document.debugConsole.style.display = "none";
	  document.debugConsole.innerHTML += "Debug Console:<br/>";
		document.body.appendChild(document.debugConsole);
	}
  //setTimeout(function() { throw new Error("[debug] " + message); }, 0);
  document.debugConsole.innerHTML += message+"<br/>";
}

/**
  Report an object as an error in the JavaScript console.
 */
function debugObject(obj) {
  var message = ""+obj+" | ";
	for (var m in obj) {
	  message += "  "+m+" | ";
	}
	debug(message);
	return message;
}

/**
  Report an element as an error in the JavaScript console.
 */
function debugElement(e) {
  var message = ""+e+" | ";
	for (var a in e.attributes) {
	  message += "  "+e.attributes[a].name+": "+e.attributes[a].value+" | ";
	}
	debug(message);
	return message;
}


